let prev = document.getElementById("prev");
	let next = document.getElementById("next");
	let ul = document.getElementById("box");
	let liList = document.querySelectorAll("#box li");
	var n = 0;
	function changeImg(){
		for(var i =0;i<liList.length-1;i++){
			liList[i].className="";
		}
		liList[n].className = "show";
	}
	//向前
	prev.onclick=function(){
		if(n===0){
			n = liList.length - 1;
		}
		else{
			n--;
		}
		changeImg()
	}
	//向后
	next.onclick=function(){
		if(n !==liList.length-1){
			n++;
		}
		else{
			n = 0;
		}
		changeImg()
	}
	//自动播放
	let autoplay = setInterval(function(){
		next.onclick()
	},2000)
	//鼠标移上停止计时器
	ul.onmouseenter = function(){
		clearInterval(autoplay);
	}
	//鼠标离开继续播放
	ul.onmouseleave=function(){
		autoplay = setInterval(()=>{
			next.onclick()
		},2000)
	}
//正则--------------------------
	var arr=[0,0]
	var usernameReg = /^[a-zA-Z]{1,20}$/;
	var psdReg=/^\w{6,18}$/;
	$("#username").blur(function(){
		if(!usernameReg.test(this.value)){
			arr[0]=0;
			$("#msg1").html("格式不正确，请输入11位手机号码").css({"display":"block","color":"red"})
		}
		else{
			$("#msg1").html("√").css({"display":"block","color":"blue"})
			arr[0]=1;
		}
	})
	$("#userpass").blur(function(){
		if(!psdReg.test(this.value)){
			$("#msg2").html("请输入数字字母下划线组合的6-18位密码").css({"display":"block","color":"red"})
			arr[1]=0;
		}
		else{
			$("#msg2").html("√").css({"display":"block","color":"blue"})
			arr[1]=1;
		}
	})
//登录
	$("#btn-4").click(function(){
		if(!arr.every(item=> item==1)){
			$("#msg3").html("登录失败!").css({"display":"block","color":"red","marginTop":"-10px"})
			// document.cookie=`=${$("#username").val()}`
			// window.location.href="weidian_dianpu.html";
		}
		else{
			ajax2013useobjandpromise({
				url:"php/login.php",
				method:"post",
				params:`username=${$("#username").val()}&userpass=${$("#userpass").val()}`
			}).then(function(data){
				console.log(data)
				if(data=="0"){
					console.log(data)
					$("#msg3").html("登录失败!").css({
						"display":"block",
						"color":"red"
					})
				}
				else{
					console.log(data)
					$("#msg3").html("登录成功!请<a href='getGoodsList.html'>前往商城</a>").css({
						"display":"block",
						"color":"blue"
					})
					document.cookie=`username=${$("#username").val()}`
				}
			})
		}
	})
